Source Code Viewer - Example 13 - ViewStaticIndexedToListAction

package name.matthewgreet.example13.action;

import java.util.Arrays;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.struts2.ActionSupport;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import name.matthewgreet.example13.form.StaticIndexedToListForm;
import name.matthewgreet.strutscommons.action.AbstractViewActionSupport;
import name.matthewgreet.strutscommons.annotation.Form;
import name.matthewgreet.strutscommons.annotation.Form.Reception;


/**
 * Struts 2 Action for testing fixed list with parameters submitted with indices. 
 */
@InterceptorRef("ViewStack")
@Results({
	@Result(name=ActionSupport.SUCCESS, location="/pages/StaticIndexedToList.jsp")
})
public class ViewStaticIndexedToListAction extends AbstractViewActionSupport {
	private static final long serialVersionUID = -6084392315736424463L;

    private Logger LOG = LogManager.getLogger(ViewStaticIndexedToListAction.class);
    
    @Form(reception = Reception.ALWAYS)
	private StaticIndexedToListForm form;
    
	private String resultText;
	
	
    @Action("/ViewStaticIndexedToList")
    @Override
    public String execute() throws Exception {
		try {
			if (form != null) {
				resultText = "Years are " + Arrays.toString(form.getYear().toArray());
			} else {
				form = new StaticIndexedToListForm();
			}
			
			return SUCCESS;
		}
		catch (Exception e) {
			LOG.error("Action failed  reason=" + e.getMessage(), e);
			return ERROR;
		}
    }
	
	public StaticIndexedToListForm getForm() {
		return form;
	}

	@Override
	public Logger getLogger() {
		return LOG;
	}

	public String getResultText() {
		return resultText;
	}

}